package com.logansoft.servicegateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author liqiye
 * @description 这个配置跟 application.yml 上配置路由一样的效果
 * @date 2021/07/16
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        // 当你访问 http://localhost:9527/homework/config/name 它会自动帮你路由到 http://localhost:9001/homework/config/name
        routes.route("homework_routh",r -> r.path("/homework/config/name").uri("http://localhost:9001/homework/config/name")).build();
        return routes.build();
    }

}
